package com.hd123.rumba.gwt.widget.client;

import java.util.ArrayList;
import java.util.Iterator;

import com.google.gwt.user.client.rpc.AsyncCallback;

public class CallbackCollection implements AsyncCallback {
  ArrayList collection = new ArrayList();

  public void addCallback(AsyncCallback callback) {
    collection.add(callback);
  }

  public void removeCallback(AsyncCallback callback) {
    collection.remove(callback);
  }

  public void onFailure(Throwable caught) {
    for (Iterator it = collection.iterator(); it.hasNext();) {
      AsyncCallback callback = (AsyncCallback) it.next();
      callback.onFailure(caught);
    }
  }

  public void onSuccess(Object result) {
    for (Iterator it = collection.iterator(); it.hasNext();) {
      AsyncCallback callback = (AsyncCallback) it.next();
      callback.onSuccess(result);
    }
  }

}
